package com.bw.yk10.func;

import java.sql.Timestamp;
import java.text.ParseException;
import java.text.SimpleDateFormat;
import java.time.ZonedDateTime;
import java.time.format.DateTimeFormatter;
import java.util.Date;
import java.util.TimeZone;

public class Test {
    public static void main(String[] args) throws ParseException {
//        Long time=1657497600000L;
//        System.out.println(checkType("aaa_time",time));

//        String timeStr="2024-06-11T19:19:04Z";
//
//        System.out.println(checkType1("create_time",timeStr));

//        String timeStr="2022-07-11 08:00:00";
        SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
//        sdf.setTimeZone(TimeZone.getTimeZone("GMT+8"));
//        System.out.println(sdf.format(sdf.parse(timeStr).getTime()));

        System.out.println(sdf.parse(new Date().toString()));
    }

    public static Object checkType(String c,Object v) {

        if(c.endsWith("_time") && v!=null&& v instanceof Long){
            Timestamp dateTimeValue =new Timestamp((Long) v);
            SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
            v = sdf.format(dateTimeValue);
        }
        return v;
    }

    public static Object checkType1(String c,Object v) {

        if(c.endsWith("_time") && v!=null&& v instanceof String){
            DateTimeFormatter formatter = DateTimeFormatter.ISO_OFFSET_DATE_TIME;
            ZonedDateTime zonedDateTime = ZonedDateTime.parse(v.toString(), formatter);
            java.util.Date date = java.util.Date.from(zonedDateTime.toInstant());
            SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
            v=sdf.format(date);
        }
        return v;
    }
}
